home *** CD-ROM | disk | FTP | other *** search
/ Pascal Super Library / Pascal Super Library (CW International)(1997).bin / LIBRARY / PAS_0493 / FNT8X8.PAS < prev    next >
Pascal/Delphi Source File  |  1993-04-14  |  5KB  |  167 lines

  1. {─ Fido Pascal Conference ────────────────────────────────────────────── PASCAL ─
  2. Msg  : 118 of 150                                                               
  3. From : Sean Palmer                         1:104/123.0          08 Apr 93  15:40 
  4. To   : All                                                                       
  5. Subj : G:Fnt8x8 unit                                                          
  6. ────────────────────────────────────────────────────────────────────────────────}
  7. { Fnt8x8 unit  v1.0 }
  8. {   03/28/93        }
  9. { various support routines for vga 8x8 text modes}
  10. { stuff for smooth text mousing and 16-color backgrounds}
  11. { Copyright (c) 1993 Sean L. Palmer }
  12. { Released to the Public Domain }
  13.  
  14. { You may distribute this freely and incorporate it with no royalties. }
  15. { Please credit me if your program uses these routines! }
  16. { If you really like them or learn something neat from me then I'd }
  17. { appreciate a small ($1 to $5) donation. }
  18. { Or contact me if you need something programmed or like my work... }
  19. { I probably have the wierdest indenting style for pascal ever! 8)  }
  20. { And, by God my stuff is optimized!! }
  21.  
  22. { Sean L. Palmer (aka Ghost)}
  23. { 2237 Lincoln St. }
  24. { Longmont, CO 80501 }
  25. { (303) 651-7862 }
  26. { also on FIDO, or at palmers@spot.colorado.edu }
  27.  
  28. unit fnt8x8;
  29. interface
  30.  
  31. procedure init;
  32. function rows:byte;
  33. procedure drawMouse(x,y:word);
  34. procedure eraseMouse;
  35.  
  36. implementation
  37.  
  38. function rows:byte;assembler;asm
  39.  mov ax,$1130; xor dx,dx; int $10;
  40.  or dx,dx; jnz @S; mov dx,24; @S: {cga/mda don't have this fn}
  41.  inc dx; mov al,dl;
  42.  end;
  43.  
  44. type tChar=array[0..7]of byte;
  45. const mouseBase=220;     {spot in charset mouse cursor uses}
  46.  
  47. {method to update chars was taken from a FIDO echo}
  48. {only works on VGA as far as I know} 
  49.  
  50. procedure accessChrMem;Inline(
  51.   $FA/                   {cli}
  52.   $BA/$C4/$03/           {mov dx,$3C4}
  53.   $B8/$02/$04/           {mov ax,$0402}
  54.   $EF/                   {out dx,ax}
  55.   $B8/$04/$07/           {mov ax,$0704}
  56.   $EF/                   {out dx,ax}
  57.   $80/$C2/$0A/           {add dl,10}
  58.   $B8/$04/$02/           {mov ax,$0204}
  59.   $EF/                   {out dx,ax}
  60.   $B8/$05/$00/           {mov ax,$0005}
  61.   $EF/                   {out dx,ax}
  62.   $B8/$06/$00/           {mov ax,$0006}
  63.   $EF);                  {out dx,ax}
  64.    
  65. procedure accessVidMem;Inline(
  66.   $BA/$C4/$03/           {mov dx,$3C4}
  67.   $B8/$02/$03/           {mov ax,$0302}
  68.   $EF/                   {out dx,ax}
  69.   $B8/$04/$03/           {mov ax,$0304}
  70.   $EF/                   {out dx,ax}
  71.   $80/$C2/$0A/           {add dl,10}
  72.   $B8/$04/$00/           {mov ax,$0004}
  73.   $EF/                   {out dx,ax}
  74.   $B8/$05/$10/           {mov ax,$1005}
  75.   $EF/                   {out dx,ax}
  76.   $B8/$06/$0E/           {mov ax,$0E06}
  77.   $EF/                   {out dx,ax}
  78.   $FB);                  {sti}
  79.  
  80. procedure SetChar(c:char;var data:tChar);begin
  81.  accessChrMem; Move(data,mem[$A000:byte(c)*32],8); accessVidMem;
  82.  end;
  83.  
  84. procedure getChar(c:char;var data:tChar);begin
  85.  accessChrMem; Move(mem[$A000:byte(c)*32],data,8); accessVidMem;
  86.  end;
  87.  
  88. const cursorData:tChar=($C0,$E0,$F0,$F8,$FC,$FE,$E0,$C0);
  89.  
  90. var
  91.  oldChars:array[0..3]of byte;
  92.  oldAdr:word;
  93.  
  94. procedure eraseMouse;var i:byte;a:word;begin
  95.  asm cli; end;
  96.  a:=oldAdr;
  97.  for i:=0 to 3 do begin
  98.   mem[$B800:a+i*2]:=oldchars[i];
  99.   if i=1 then inc(a,160-4);
  100.   end;
  101.  asm sti;end;
  102.  end;
  103.  
  104. procedure copyChar(s,d:char);var i:tChar;begin
  105.  getchar(s,i);
  106.  setChar(d,i);
  107.  end;
  108.  
  109. procedure drawMouse(x,y:word);
  110. var xl,yl,xr:byte;a:word;i:byte; pc,pd:^byte;
  111. begin
  112.  xl:=x and 7; yl:=y and 7; xr:=8-xl; x:=x shr 3; y:=y shr 3;
  113.  a:=y*160+x*2; oldAdr:=a;
  114.  for i:=0 to 3 do begin
  115.   oldchars[i]:=mem[$B800:a+i*2];
  116.   copychar(char(oldChars[i]),char(mouseBase+i));
  117.   mem[$B800:a+i*2]:=mouseBase+i;
  118.   if i=1 then inc(a,160-4);
  119.   end;
  120.  pc:=ptr($A000,mouseBase*32+yl);
  121.  pd:=@cursorData;
  122.  accessChrMem;
  123.  for i:=0 to 7 do begin
  124.   pc^:=pc^ or (pd^ shr xl); inc(word(pc),32);
  125.   pc^:=pc^ or (pd^ shl xr); dec(word(pc),31);
  126.   inc(word(pd));
  127.   inc(yl); if yl=8 then inc(word(pc),56);  {handle wrap to next row}
  128.   end;
  129.  accessVidMem;
  130.  end;
  131.  
  132. procedure init;assembler;asm
  133.  mov ax,$1202; mov bl,$30; int $10; {select 400 scan lines}
  134.  mov ax,3; int $10; {text mode}
  135.  mov bl,0;mov ax,$1003; int $10;  {no blinking, enable 16 colors for
  136. background}  mov ax,$1112; mov bl,0; int $10; {load 8x8 character set}
  137.  end;
  138.  
  139. var oldmode:byte;
  140. function vgaPresent:boolean;assembler;asm
  141.  mov ah,$F; int $10; mov oldMode,al;  {save old Gr mode}
  142.  mov ax,$1A00; int $10;    {check for VGA/MCGA}
  143.  cmp al,$1A; jne @ERR;     {no VGA Bios}
  144.  cmp bl,7; jb @ERR;        {is VGA or better?}
  145.  cmp bl,$FF; jnz @OK;
  146. @ERR: xor al,al; jmp @EXIT;
  147. @OK: mov al,1;
  148. @EXIT:
  149.  end;
  150.  
  151. var exitSave:pointer;
  152.  
  153. procedure done;far;begin;
  154.  exitProc:=exitSave;
  155.  asm mov al,oldmode; xor ah,ah; int $10;end;
  156.  end;
  157.  
  158. procedure blinkOn;assembler;asm mov bl,1;mov ax,$1003; int $10;end;
  159.  
  160. begin
  161.  if vgaPresent then begin
  162.   init;
  163.   exitSave:=exitProc;exitProc:=@done;
  164.   end
  165.  else begin writeln('Need VGA.'); halt(1);end;
  166.  end.
  167.